<template>
	<view>
		<cu-custom bgColor="bg-white-nav" isBack>
		    <block slot="content">绑定支付宝</block>
		</cu-custom>
		<view class="from-container">
			<u--form labelPosition="left" labelWidth="100" :labelStyle="labelStyle" :model="from" :rules="rules"
				ref="uForm">
				<u-form-item label="支付宝账号" prop="account" borderBottom>
					<u--input v-model="from.account" placeholder="请输入支付宝账号" border="none"></u--input>
				</u-form-item>
				<u-form-item label="姓名" prop="name" borderBottom>
					<u--input v-model="from.name" placeholder="请输入姓名" border="none"></u--input>
				</u-form-item>
				<u-form-item label="手机号" prop="phone" borderBottom>
					<u--input v-model="from.phone" placeholder="请输入手机号" border="none"></u--input>
				</u-form-item>
				<u-form-item label="验证码" prop="code" borderBottom>
					<u--input v-model="from.phone" placeholder="请输入短信验证码" border="none"></u--input>
					<template #right>
						<u-code :seconds="seconds"ref="uCode" @change="codeChange"></u-code>
						<view @tap="getCode" class="code">{{tips}}</view>
					</template>
				</u-form-item>
			</u--form>
			<button @click="submit" class="btn">确定</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				from: {
					account: '',
					name: '',
					phone: '',
					code: ''
				},
				rules: {
					account: {
						required: true,
						message: '请输入支付宝账号',
						trigger: ['blur']
					},
					name: {
						required: true,
						message: '请输入姓名',
						trigger: ['blur']
					},
					phone: {
						required: true,
						message: '请输入手机号',
						trigger: ['blur']
					},
					code: {
						required: true,
						message: '请输入短信验证码',
						trigger: ['blur']
					},
				},
				labelStyle: {
					fontSize: '30rpx',
					color: '#333'
				},
				tips: '',
				seconds: 60,
			}
		},
		methods: {
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #fff;
	}

	.from-container {
		padding: 30rpx;
		.btn {
			margin-top: 80rpx;
			height: 96rpx;
			line-height: 96rpx;
			background: #3662EC;
			border-radius: 16rpx;
			color: #fff;
			font-size: 30rpx;
			font-weight: 600;
			letter-spacing: 4rpx;
		}
	}
	
	::v-deep .u-form-item__body {
		padding: 34rpx 0;
	}
	.code {
		color: #3662EC;
		font-size: 30rpx;
	}
</style>